/**  
 * All rights Reserved, Designed By <a href="www.itttq.com" target="_blank">www.itttq.com</a>
 * @date:   2017-07-21 11:42:21
 * @Copyright: 2017 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */
package com.itttq.gshop.pc.controller.user;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.itttq.gshop.domain.po.UserInfoPo;
import com.itttq.gshop.generic.cmpt.annotation.Auth;
import com.itttq.gshop.generic.connector.IUserFavoritesConnector;
import com.itttq.gshop.generic.controller.GenericController;
@Auth
@RestController
@RequestMapping("favorite")
public class FavoritesController extends GenericController {
	private static final long serialVersionUID = -4455776149450226L;
	@Autowired
	private IUserFavoritesConnector userFavoritesConnector;
	
	@RequestMapping("list.html")
    public ModelAndView getUserFavorites(HttpServletRequest request) {
		ModelAndView mv = new ModelAndView("/mine/favorite");
		mv.addObject("favorites", userFavoritesConnector.getUserFavoritess(this.getUserFromSession(request).getId()).getData());
        return mv;
    }
	
	/**
	 * 关注商品
	 * 
	 * @param wareId	商品ID
	 * @param userId		用户ID
	 * @param username		用户名
	 * @Author 迷蝶
	 * @return Integer
	 */
	@RequestMapping("fav/{wareId}.html")
	public Integer favorite(@PathVariable("wareId") int wareId, HttpServletRequest request) {
		UserInfoPo user = this.getUserFromSession(request);
		return userFavoritesConnector.favorite(wareId, user.getId(), user.getUsername());
	}
	/**
	 * 用户取消关注商品
	 * 
	 * @param wareId	商品ID
	 * @param userId		用户ID
	 * @Author 迷蝶
	 * @return Integer
	 */
	@RequestMapping("unfav/{wareId}.html")
	public Integer unFavorite(@PathVariable("wareId") int wareId, HttpServletRequest request) {
		return userFavoritesConnector.unFavorite(wareId, this.getUserIdFromSession(request));
	}
	
	/**
	 * 批量取消收藏关注商品
	 * 
	 * @param ids			关注记录ID集合，多个以逗号分隔
	 * @Author 迷蝶
	 * @return Integer
	 */
	@RequestMapping("unfavBatch.html")
	public Integer unFavoriteBatch(String ids, HttpServletRequest request) {
		return userFavoritesConnector.unFavoriteBatch(this.getUserIdFromSession(request), ids);
	}
}